package client

import (
	"log"
	"luiz/crawler/engine"
	"luiz/crawler_distributed/prcsupport"
)

func ItemSaver(host string) (chan engine.Item, error) {
	cli, err := prcsupport.NewCli(host)
	if err != nil {
		return nil, err
	}
	c := make(chan engine.Item)
	go func() {
		itemCount := 0
		for {
			house := <-c
			itemCount++
			//call rpc
			res := ""
			err := cli.Call("ItemSaverService.Save", house, &res)
			if err != nil {
				log.Printf("error:%v", err)
			}

		}
	}()
	return c, nil
}
